package com.example.je_0309;

import com.example.je_0309.modle.Student;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;
import java.util.List;

@RequestMapping("/request")
@RestController
public class RequestController {
    @RequestMapping("/hello")
    public String  hello(){
        return "Hello JE";
    }


    @RequestMapping("/m1")
    public String  m1(String name){
        return "接受参数 name：" +  name;
    }

    @RequestMapping("/m2")
    public String  m2(Integer age){
        return "接受参数 age：" +  age;
    }

    @RequestMapping("/m3")
    public String m3(int age) {
        return "接受参数 age：" +  age;
    }

    @RequestMapping("/m4")
    public String m4(String name ,Integer age) {
        return "接收参数 name：" +   name + "age：" + age;
    }

    @RequestMapping("/m5")
    public String m5(Student student) {
        return "接收参数：" + student;
    }

    @RequestMapping("/m6")
    public String m6(@RequestParam("name") String userName) {
        return "接收参数：name：" + userName;
    }

    @RequestMapping("/m7")
    public String m7(@RequestParam(value = "name",required = false) String userName) {
        return "接收参数：name：" + userName;
    }

    @RequestMapping("/m8")
    public String m8(String[] array) {
        return "接收到参数 array：" +  Arrays.toString(array);
    }

    @RequestMapping("/m9")
    public String m9(@RequestParam(required = false) List<Integer> list) {
        return "接收到参数 list：" + list;
    }


    /*
        使用JSON传递
     */

    @RequestMapping("/m10")
    public String m10(@RequestBody Student student) {
        return "接收到参数 student：" + student;
    }

    @RequestMapping("/article/{article}")
    public String m11(@PathVariable("article") Integer articleId) {
        return "收到参数 articleId："+articleId;
    }

    @RequestMapping("/article/{articleId}/{name}")
    public String m12(@PathVariable("articleId") Integer articleId,@PathVariable("name") String name) {
        return articleId + "    " + name;
    }


    /*
    文件传输
     */
    @RequestMapping("/m11")
    public String m13(@RequestPart("file")MultipartFile file) {
        String originalFilename = file.getOriginalFilename();
        return "接到到文件, 文件名称:"+originalFilename;
    }
}
